package com.yunji.web.base;

import com.yunji.base.business.SiteLocationTypeBusiness;
import com.yunji.base.dto.SiteLocationTypeDTO;
import com.yunji.base.params.SiteLocationTypeParam;
import com.yunji.base.vo.SiteLocationTypeVO;
import com.yunji.common.base.response.Response;
import com.yunji.common.base.response.ResponseHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@RestController
@Api(tags = "管理端-点位类型")
@RequestMapping("/location/type")
public class SiteLocationTypeController {

    @Resource
    private SiteLocationTypeBusiness business;

    @ApiOperation("获取点位类型列表")
    @GetMapping("/list")
    public Response<List<SiteLocationTypeVO>> list(@Valid SiteLocationTypeParam params) {
        return ResponseHelper.successWithPage(business.searchPage(params),params.getTotal());
    }

    @ApiOperation("新增点位类型")
    @PostMapping("/create")
    @PreAuthorize("@ss.hasPermi('area:type:add')")
    public Response<Long> create(@RequestBody SiteLocationTypeDTO dto){
        return ResponseHelper.success(business.create(dto));
    }

    @ApiOperation("修改点位类型")
    @PutMapping("/update")
    @PreAuthorize("@ss.hasPermi('area:type:edit')")
    public Response<String> update(@RequestBody SiteLocationTypeDTO dto){
        business.update(dto);
        return  ResponseHelper.success();
    }

    @ApiOperation("删除点位类型")
    @DeleteMapping("/delete/{ids}")
    @PreAuthorize("@ss.hasPermi('area:type:remove')")
    public Response<String> delete(@PathVariable Long... ids){
        business.delete(ids);
        return ResponseHelper.success();
    }

    @ApiOperation("获取点位详细信息")
    @GetMapping("/getInfo/{id}")
    public Response<SiteLocationTypeVO> getInfo(@PathVariable("id") Long id){
        return ResponseHelper.success(business.getInfo(id));
    }

}
